package com.bangf.repo;

import com.bangf.domain.FpResident;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ResidentRepo extends JpaRepository<FpResident,Integer> {

    @Query(value =  "SELECT count(*) FROM fp_resident " +
                    "WHERE household_id = ?1",nativeQuery = true)
    Integer countByHouseholdId(Integer householdId);


    @Query(value =  "SELECT count(*) FROM fp_resident " +
                    "WHERE town_id = ?1",nativeQuery = true)
    Integer countByTownId(Integer townId);

    @Query(value =  "SELECT * FROM bangf.fp_resident " +
                    "WHERE is_db = 1 AND " +
                    "household_id = ?1",nativeQuery = true)
    List<FpResident> findWbByHouseholdId(Integer householdId);

    @Query(value =  "SELECT * FROM fp_resident " +
                    "limit ?1,?2",nativeQuery = true)
    List<FpResident> findLimit(Integer index, Integer limit);


    @Query(value =  "SELECT * FROM fp_resident " +
                    "where household_id = ?1",nativeQuery = true)
    List<FpResident> findByHouseholdId(Integer householdId);
}
